package com.xingmang.admin.controller;

import com.xingmang.common.constant.ResponseData;
import com.xingmang.common.constant.ResultBean;
import com.xingmang.common.utils.FileUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @auther: hansom
 * @Version: 1.0
 * @create 2023/6/30 13:48
 */
@RestController
@RequestMapping("/admin/upload")
@Api(tags = "文件上传")
public class UploadController {

    @PostMapping("upload")
    @ApiOperation("上传文件")
    public ResultBean upload(MultipartFile multiFile, HttpServletRequest req) {
        Map<String, Object> upload = FileUtils.upload(multiFile, req);
        return ResponseData.success(upload.get("url").toString());
    }
}
